package com.kdgc.power.chess.service;

import com.kdgc.power.common.util.StringUtil;
import com.kdgc.power.fw.service.BaseService;
import com.kdgc.power.fw.service.ChessService;
import org.beetl.sql.core.page.PageResult;
import org.springframework.stereotype.Service;
import com.kdgc.power.chess.entity.ChinaChess;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@Service
public class ChinaChessService extends BaseService<ChinaChess> {
    @Resource
    private ChessService chessService;
    public PageResult<Map<String, Object>> getPage(String sqlId, Map<String, Object> paras, Integer page, Integer rows) {
        PageResult<Map<String, Object>> result = super.getPage(sqlId, paras, page, rows);
        List<Map<String, Object>> mapList = result.getList();
        mapList.forEach(chess->{
            try {
                chess.put("svg",chessService.fenToSvg(StringUtil.toString(chess.get("chessFen"))));
            } catch (IOException e) {
                chess.put("svg","");
            }
        });
        result.setList(mapList);
        return  result;
    }
}